package com.battle.service.repository.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.battle.pojo.entity.TrainingGroup;
import com.battle.pojo.entity.TrainingSoloDetails;
import com.battle.pojo.vo.trainingSoloDetails.GetTrainingSoloDetailsListVo;
import com.battle.service.mapper.TrainingSoloDetailsMapper;
import com.battle.service.repository.in.TrainingSoloDetailsRepository;
import nirvana.core.repository.Repository;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
    import com.battle.pojo.dto.trainingSoloDetails.*;
    import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
* 【描 述】：
* 【环 境】：J2SE
* 【详 细】：
*
*/
@Service
public class TrainingSoloDetailsRepositoryImpl extends Repository< TrainingSoloDetailsMapper , TrainingSoloDetails> implements TrainingSoloDetailsRepository {

private final TrainingSoloDetailsMapper mapper;

public TrainingSoloDetailsRepositoryImpl(TrainingSoloDetailsMapper mapper) {
this.mapper = mapper;
}

    /**
    * 搜索单人训练
    * @param dto
    * @return
    */
    @Override
    public Page<GetTrainingSoloDetailsListVo> selectTrainingSoloDetails(SelectTrainingSoloDetailsDto dto){

    return mapper.selectTrainingSoloDetails(dto);
    }

@Override
public  Map<Long, TrainingSoloDetails> getMap(List<Long> ids){
    Map<Long, TrainingSoloDetails> map = new HashMap<>();

    if (CollectionUtil.isNotEmpty(ids)) {
        List<TrainingSoloDetails> list =listByIds(ids);
        if (CollectionUtil.isNotEmpty(list)) {
        map = list.stream().collect(Collectors.toMap(TrainingSoloDetails::getId, pojo -> pojo));
         }
        }
        return map;
    }

    @Override
    public List<TrainingSoloDetails> selectSoleDetailsByPath(List<Long> organizationIds, LocalDate startDate, LocalDate endDate,Long trainingProgramId) {
        return mapper.selectList(new LambdaQueryWrapper<>(new TrainingSoloDetails())
                .in(CollectionUtil.isNotEmpty(organizationIds),TrainingSoloDetails::getDepartmentId, organizationIds)
                .ge(TrainingSoloDetails::getTrainingDate, startDate)
                .le(TrainingSoloDetails::getTrainingDate, endDate)
                .eq(ObjectUtil.isNotNull(trainingProgramId), TrainingSoloDetails::getTrainingProgramId, trainingProgramId));
    }
}